package com.liuwei.spring.cloud.common.utils;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;

import java.util.*;


/**
 * Lambda 表达式通用工具类
 * @author liuwei19
 */
@Slf4j
public class Lambdas {
	
	@Data
	public static class User{
		private int id;
		private String name;
		private Date date;
		private float money;
		public User(int id ,String name,Date date){
			this.id = id;
			this.name = name;
			this.date = date;
			this.money = new Random().nextFloat();
		}
	}

	/**
	 * 判空返回默认值
	 * @param value
	 * @param defaultValue
	 * @param <T>
	 * @return
	 */
	public static <T> T defaultIfNull(T value, T defaultValue){
		if(!ObjectUtils.isEmpty(value)){
			return value;
		}else{
			return defaultValue;
		}
	}
}
